`
https://leetcode.cn/problems/k-radius-subarray-averages/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number[]}
 */
var getAverages = function (nums, k) {
  // 半径为 k ，转换为长度
  k = k * 2 + 1
  const n = nums.length
  const res = new Array(n).fill(-1)
  let sum = 0
  let left = 0, right = 0

  // 维护一个长度为 k 的
  while (right < n) {
    const n1 = nums[right++]
    sum += n1

    const len = right - left
    if (len >= k) {
      // 计算中心点，更新答案
      const targetIdx = right - Math.floor(len / 2) - 1
      res[targetIdx] = Math.trunc(sum / len)
      const n2 = nums[left++]
      sum -= n2
    }
  }

  return res
};